package carlyang;

import java.io.BufferedReader;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class FileRead {
	public static Path testpath = Paths.get("E:/adt_workplace/1.txt");
	public static Path path = Paths.get("E:/adt_workplace/2.txt");
	public static Path path2 = Paths.get("E:/adt_workplace/test/src/carlyang/FileRead.java");
	public static Path debugPath = Paths.get("E:/adt_workplace/debug.txt");
	public FileRead() {
		// TODO Auto-generated constructor stub
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("System.out begin print to file");
		SystemOutToFile.start(debugPath);
		Charset charsetChineseSimple = Charset.forName("GB2312");
		Charset charsetDef = Charset.defaultCharset();//Ĭ��ΪGBK
		System.out.println("defaultCharset:"+charsetDef);
		Charset charsetUsascii = Charset.forName("US-ASCII");//�޷���ȡ����
		try (InputStream inputStream = Files.newInputStream(path, StandardOpenOption.READ)){
			System.out.println(inputStream.available());
			byte[] buf = new byte[20];
			inputStream.skip(0);//skip some bytes
			inputStream.read(buf);//
			System.out.println(FacadeChatUtils.bytesToHexString(buf).trim());
		} catch (Exception e) {
			// TODO: handle exception
			//System.out.println(e.toString());
			e.printStackTrace();
		}
		//ʹ��BufferedReader��ȡ�ļ�
		try (BufferedReader bReader = Files.newBufferedReader(path2,charsetDef)){
			String line = bReader.readLine();
			while (line != null) {
				System.out.println(line);
				line = bReader.readLine();
			}
		} catch (Exception e) {
			// TODO: handle exception
			//System.out.println(e.toString());
			e.printStackTrace();
		}
		SystemOutToFile.close();
		System.out.println("RUN OVER");
		SystemOutToFile.start(testpath);
		System.out.println("SystemOutToFile testpath");
		SystemOutToFile.close();
		System.out.println("RUN OVER");
	}

}
